/*
 * @Author: 蔡霸霸
 * @Date: 2020-04-22 14:14:59
 * @LastEditors: 蔡霸霸
 * @LastEditTime: 2020-06-18 11:16:26
 * @FilePath: \Nuxt_music\nuxt.config.js
 */
// eslint-disable-next-line nuxt/no-cjs-in-config
const defaultSettings = require('./static/default')

let path = ''
if (process.env.PATH_TYPE === 'local') {
  path = 'http://api.蔡霸霸.top/'
} else {
  path = 'http://localhost:9998/'
}

export default {
  mode: 'universal',
  /*
   ** Headers of the page
   */
  head: {
    title: defaultSettings.title || '',
    meta: [
      {
        charset: 'utf-8'
      },
      {
        name: 'viewport',
        content: 'width=device-width, initial-scale=1'
      },
      {
        hid: 'keywords',
        name: 'keywords',
        content: defaultSettings.keywords || ''
      },
      {
        hid: 'description',
        name: 'description',
        content: defaultSettings.description || ''
      },
      {
        hid: 'author',
        name: 'author',
        content: '蔡霸霸'
      }
    ],
    link: [
      {
        rel: 'icon',
        type: 'image/x-icon',
        href: '/favicon.ico'
      }
    ]
  },
  /*
   ** Customize the progress-bar color
   */
  loading: {
    color: '#fff'
  },
  env: {
    PATH_TYPE: process.env.PATH_TYPE
  },
  /*
   ** Global CSS
   */
  css: ['ant-design-vue/dist/antd.min.css', 'normalize.css/normalize.css'],
  /*
   ** Plugins to load before mounting the App
   */
  plugins: ['@/plugins/antd-ui', '@/plugins/axios.js'],
  router: {
    middleware: ['route', 'header'] // 即每次路由跳转会调用该中间件
    // 多个中间件写法
    // middleware: ['route']
  },
  /*
   ** Nuxt.js dev-modules
   */
  buildModules: [
    // Doc: https://github.com/nuxt-community/eslint-module
    '@nuxtjs/eslint-module'
  ],
  /*
   ** Nuxt.js modules
   */
  modules: [
    // Doc: https://axios.nuxtjs.org/usage
    '@nuxtjs/axios'
  ],
  /*
   ** Axios module configuration
   ** See https://axios.nuxtjs.org/options
   */
  axios: {
    proxy: true,
    credentials: true,
    prefix: '/api'
  },
  proxy: {
    '/api': {
      target: path,
      pathRewrite: {
        '^/api': '',
        changeOrign: true
      }
    }
  },
  /*
   ** Build configuration
   */
  build: {
    styleResources: {
      scss: './static/css/all.scss'
    },
    extractCSS: { allChunks: true }
  }
}
